package top.heliming.rabbitmq.rabbitmqdemo.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * description: //TODO
 *
 * @author: heliming
 * @date:2019/06/06 下午 10:18
 */
public class ConnectionUtil {
  /**
   * 建立与RabbitMQ的连接
   * @return
   * @throws Exception
   */
  public static Connection getConnection() throws Exception {
    //定义连接工厂
    ConnectionFactory factory = new ConnectionFactory();
    //设置服务地址
    factory.setHost("10.0.1.224");
    //端口
    factory.setPort(5672);
    //设置账号信息，用户名、密码、vhost
    factory.setVirtualHost("/leyou");
    factory.setUsername("leyou");
    factory.setPassword("leyou");
    // 通过工程获取连接
    Connection connection = factory.newConnection();
    return connection;
  }
}
